package net.awpspace.mobile.management.house;

import java.io.InputStream;

import javax.microedition.media.Manager;
import javax.microedition.media.Player;

public class AudioManager {

	private static AudioManager instance;
	public static String BUTTON = "/housedata/button.mp3";
	public static String FAILURE = "/housedata/failure.mp3";
	public static String SUCCESS = "/housedata/success.mp3";

	private AudioManager() {

	}

	public static AudioManager getInstance() {
		if (instance == null)
			instance = new AudioManager();
		return instance;
	}

	public void play(String file) {
		createThread(file).start();
	}

	public Thread createThread(final String file) {
		return new Thread(new Runnable() {

			public void run() {
				try {
					InputStream in = getClass().getResourceAsStream(file);
					Player player = Manager.createPlayer(in, "audio/mpeg");
//					player.prefetch();
					player.start();
				} catch (Exception e) {
					System.out.println(e.toString());
					return;
				}
			}
		});
	}

}
